package com.user.controller;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import javax.websocket.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bean.User;
import com.user.service.UserService;
@Controller
public class UserController {
	@Autowired
    private UserService userserviceimp;
	@RequestMapping("/userLogin")
	public String login(User user,HttpSession session,String status,Model model) {
		if(status.equals("用户")) {
			return userserviceimp.check(user,session,model);
		}
		else {
			return userserviceimp.adminLogin(user,model,session);
		}
	}
	@RequestMapping("/insertUser")
    public String insertUser(@Valid @ModelAttribute User user,BindingResult result, Model model) {
    	return userserviceimp.insertUser(user,result,model);
	}
	@RequestMapping("/CheckAddUser")
    public String CheckAddUser(@ModelAttribute User user) {
    	return "user/reguser";
	}
	@RequestMapping("/i18n")
    public String i18n(User user,HttpSession session) {
   	 return "user/index";
	}
	
	@RequestMapping("/InLogin")
    public String getUserInfo(HttpSession session) {
	User user=(User) session.getAttribute("user");
	if(user==null) {
		return "user/nologin";
	}else {
		return "user/updateuser";
	}
	}
	@RequestMapping("/updateInfo1")
    public String updateInfo1(HttpSession session,User user, Model model) {
	 return userserviceimp.updateInfo1(session,user,model);
	}
	
	@RequestMapping("/UserSelectPetByPname")
	public String UserSelectPetByPname(Model model,String pname) {
		return userserviceimp.UserSelectPetByPname(pname,model);
	}
	@RequestMapping("/selectbyPettype")
	public String selectbyPettype(int tid,Model model) {
		return userserviceimp.selectbyPettype(tid, model);
	}
	
	@RequestMapping("/UserSelectPet")
	public String UserSelectPet(Model model) {
		return userserviceimp.UserSelectPet(model);
	}
	
	
	@RequestMapping("/selectPetByID")
	public String selectTypeByID(int pid,Model model) {
		return userserviceimp.selectPetByID(pid, model);
	}
	
	@RequestMapping("/MainPet")
	public String MainPet(Model model) {
		return userserviceimp.MainPet(model);
	}
	@RequestMapping("/login")
	public String mylogin(Model model) {
		return "login";
	}
	
}
